package com.wdciti.sccp.iot.gateway.autoconfig;

import org.apache.iotdb.rpc.IoTDBConnectionException;
import org.apache.iotdb.session.Session;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


/**
 * @Author xxing
 * @Description iotdb自动配置类
 * @Date 2023/7/17
 **/
@Configuration()
public class IotDBSessionConfiguration {

    @Value("${iotdb.host}")
    private String host;
    @Value("${iotdb.port}")
    private int port;
    @Value("${iotdb.username}")
    private String username;
    @Value("${iotdb.password}")
    private String password;


    @Bean
    public Session iotDBSession() throws IoTDBConnectionException {
        Session session = new Session.Builder()
                .host(host)
                .port(port)
                .username(username)
                .password(password)
                .enableRedirection(true)
                .build();
        session.open(false);
        return session;
    }
}
